package org.example.controller;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.example.domain.dto.LoginDto;
import org.example.domain.model.Result;
import org.example.service.IUserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
//@CrossOrigin("*")
public class AuthenticationController {

    private IUserService userService;
    private Log logger = LogFactory.getLog(AuthenticationController.class);

    public AuthenticationController(IUserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/token")
    public Result auth(@RequestBody LoginDto loginDto) {
        logger.info(String.format("username: %s, password: %s", loginDto.getUsername(), loginDto.getPassword()));
        return userService.login(loginDto);
    }
}
